package name.bingo.bing.pay.service.message.mqservice;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;

import javax.jms.*;

/**
 * create by yanbing on 2018/8/28 10:07
 */
@Component
@EnableScheduling
public class Producer {

    @Autowired
    private Topic topic;
    @Autowired
    private JmsTemplate jmsTemplate;
    /**
     * 发送消息，destination是发送到的队列，message是待发送的消息
     * @param destination
     * @param message
     */
    public void sendMessage(Destination destination, final String message) {
        //System.out.println(jmsTemplate.getDeliveryMode());
        jmsTemplate.convertAndSend(destination, message);
    }
    /**
     * 发布消息，message是待发送的消息
     * @param message
     */
    public void sendTopicMessage(final String message) {
        //System.out.println(jmsTemplate.getDeliveryMode());
        jmsTemplate.convertAndSend(topic,message);
    }

}

